#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int x, y, z;
int a[N], b[N], c[N], acnt, bcnt, ccnt;
int ans;
void solve() {
  acnt = bcnt = ccnt = ans = 0;
  cin >> n;
  rep(i, 1, n) {
    cin >> x >> y >> z;
    int mx = max({x, y, z});
    ans += mx;
    if (x == mx)
      a[++acnt] = x - max(y, z);
    else if (y == mx)
      b[++bcnt] = y - max(x, z);
    else
      c[++ccnt] = z - max(x, y);
  }
  if (acnt > n / 2) {
    sort(a + 1, a + acnt + 1);
    rep(i, 1, acnt - n / 2) ans -= a[i];
  }
  if (bcnt > n / 2) {
    sort(b + 1, b + bcnt + 1);
    rep(i, 1, bcnt - n / 2) ans -= b[i];
  }
  if (ccnt > n / 2) {
    sort(c + 1, c + ccnt + 1);
    rep(i, 1, ccnt - n / 2) ans -= c[i];
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}